package Week6;

import java.awt.Color;
import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.Iterator;


public class BoundingBox {
//Bounding boxes are used for ArrayLists of Points, like PolyLines and Polygons.
		
//	Declare member variables.
	private ArrayList<Point> polypoints;
	private ArrayList<Point> boundingBox;
	private Point ul, lr;
	


	//	Constructor for bounding box of ArrayList<Point>.
	public BoundingBox(ArrayList<Point> polypoints){
		this.polypoints = polypoints;

		Iterator<Point> itr = polypoints.iterator();
		
		double highX, highY;
		double lowX, lowY;
		highX = highY = Double.MIN_VALUE;
		lowX = lowY = Double.MAX_VALUE;
				
		Point ul = new Point();
		Point lr = new Point();	
		this.ul = ul;
		this.lr = lr;
		
		while(itr.hasNext()){
		
			Point tmp = itr.next();
		
			highX = Math.max(highX, tmp.getX());
			highY = Math.max(highY, tmp.getY());
			lowX = Math.min(lowX, tmp.getX());
			lowY = Math.min(lowY, tmp.getY());		
		
			ul.setX(lowX);
			ul.setY(highY);			
			lr.setX(highX);
			lr.setY(lowY);		
		}
		
		boundingBox = new ArrayList<Point>();
		boundingBox.add(ul);
		boundingBox.add(lr);
		
	}
	
	//	Constructor for bounding box of Rectangle.
	public BoundingBox(Rectangle rct){
				
		Point ul = new Point();
		Point lr = new Point();	
		this.ul = ul;
		this.lr = lr;
		
		ul.setX(rct.getPt().getX());
		ul.setY(rct.getPt().getY());			
		lr.setX(rct.getPt().getX() + rct.getSide1());
		lr.setY(rct.getPt().getY() + rct.getSide2());
		
		boundingBox = new ArrayList<Point>();
		boundingBox.add(ul);
		boundingBox.add(lr);	
	}
	
    	
	//	Constructor for bounding box of Circle.
	public BoundingBox(Circle cir){
		
		Point ul = new Point();
		Point lr = new Point();	
		this.ul = ul;
		this.lr = lr;
		
		ul.setX(cir.getPt().getX() - ((int) cir.getRad()));
		ul.setY(cir.getPt().getY() - ((int) cir.getRad()));			
		lr.setX(cir.getPt().getX() + ((int) cir.getRad()));
		lr.setY(cir.getPt().getY() + ((int) cir.getRad()));
		
		boundingBox = new ArrayList<Point>();
		boundingBox.add(ul);
		boundingBox.add(lr);	
	}

	
	//	Constructor for bounding box of Point.	
	public BoundingBox(Point pnt){
		
		Point ul = new Point();
		Point lr = new Point();	
		this.ul = ul;
		this.lr = lr;
		
		ul.setX(pnt.getX());
		ul.setY(pnt.getY());			
		lr.setX(pnt.getX());
		lr.setY(pnt.getY());
		
		boundingBox = new ArrayList<Point>();
		boundingBox.add(ul);
		boundingBox.add(lr);		
	}
	
	
	
	//Getter and setters
	
	public Point getUl() {
		return ul;
	}

	public void setUl(Point ul) {
		this.ul = ul;
	}

	public Point getLr() {
		return lr;
	}

	public void setLr(Point lr) {
		this.lr = lr;
	}
	
	public ArrayList<Point> getBoundingBox() {
		return boundingBox;
	}
	

		
}
